/*-------------------------------------------------------------------------------------------------------------------------
	Warn Someone
-------------------------------------------------------------------------------------------------------------------------*/

local PLUGIN = {}
PLUGIN.Title = "Warn"
PLUGIN.Description = "Warn someone."
PLUGIN.Author = "Overv"
PLUGIN.ChatCommand = "warn"
PLUGIN.Usage = "<player> <reason>"
PLUGIN.Privileges = { "Warn" }

function PLUGIN:Call( ply, args )
	if ( ply:EV_HasPrivilege( "Warn" ) ) then
		local pl = evolve:FindPlayer( args[1] )
		
		if ( #pl > 1 ) then
			evolve:Notify( ply, evolve.colors.white, "Did you mean ", evolve.colors.red, evolve:CreatePlayerList( pl, true ), evolve.colors.white, "?" )
		elseif ( #pl == 1 ) then
			if ( #args > 1 ) then
				local msg = table.concat( args, " ", 2 )
				local newmsg = string.gsub(msg," ","%%20")
				local newplayer = string.gsub(evolve:PlayerLogStr( ply )," ","%%20")
				local reported = string.gsub(evolve:PlayerLogStr( pl[1] )," ","%%20")
				
				http.Get("http://www.matthewjeanes.info/report.php?report=".. newplayer .."%20warned%20".. reported .."%20with%20reason:%20".. newmsg .."" , "", function() end)
				
				for _, admin in ipairs( player.GetAll() ) do
					if ( admin:EV_IsAdmin() ) then evolve:Notify( admin, evolve.colors.red, ply:Nick() .. " warned " .. pl[1]:Nick() .. " with reason: ", evolve.colors.white, msg ) end
				end
			else
				evolve:Notify( ply, evolve.colors.red, "No reason specified!" )
			end
		else
			evolve:Notify( ply, evolve.colors.red, evolve.constants.noplayersnoimmunity )
		end
	else
		evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
	end
end

evolve:RegisterPlugin( PLUGIN )